package com.rsk.service.curriculum.impl;


import java.util.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.dubbo.config.annotation.Service;
import com.rsk.dao.curriculum.RskCourseEvaluateRepository;
import com.rsk.dao.extend.curriculum.RskCourseEvaluateExtend;
import com.rsk.dao.utils.SearchDataUtils;
import com.rsk.entity.curriculum.RskCourseEvaluate;
import com.rsk.service.curriculum.RskCourseEvaluateService;
import com.rsk.utils.algorithm.SnowflakeIdWorker;
import com.rsk.utils.tools.PageUtils;


@Service(interfaceClass = RskCourseEvaluateService.class)
public class RskCourseEvaluateServiceImpl implements RskCourseEvaluateService{
	
	@Autowired
	private RskCourseEvaluateRepository rskCourseEvaluateRepository;
	
    @Autowired
    private RskCourseEvaluateExtend rskCourseEvaluateExtend;
    
    @Autowired
    private SearchDataUtils searchDataUtils;



	@SuppressWarnings({ "unchecked", "rawtypes" })
	public PageUtils<Map> selectRskCourseEvaluate(Long courseId, Integer nowPage, Integer pageSize) {
		Map<String, Object> map = rskCourseEvaluateExtend.selectskCourseEvaluateByPage(courseId);
        String sql = map.get("sql").toString();
        String countSQL =  map.get("countSQL").toString();
        Map<String,Object> paramMap = (Map<String, Object>) map.get("paramMap");
        PageUtils<Map> page = searchDataUtils.searchByPage(nowPage, pageSize, sql, countSQL, paramMap, Map.class);
        return page;
	}

	@Transactional
	public int saveRskCourseEvaluate(Long courseId, String comments,
			Date commentTime, Integer commentStatus, Integer commentSource,
			String commentUser, String commentPhoto, Integer isTop,
			Long operatorUser) {
		RskCourseEvaluate rskCourseEvaluate = new RskCourseEvaluate();
		rskCourseEvaluate.setId(SnowflakeIdWorker.generateId(true));
		rskCourseEvaluate.setCourseId(courseId);
		rskCourseEvaluate.setComments(comments);
		rskCourseEvaluate.setCommentTime(commentTime);
		rskCourseEvaluate.setCommentUser(commentUser);
		rskCourseEvaluate.setCommentPhoto(commentPhoto);
		rskCourseEvaluate.setCommentStatus(commentStatus);
		rskCourseEvaluate.setCommentSource(commentSource);
		rskCourseEvaluate.setIsTop(isTop);
		rskCourseEvaluate.setIsDel(0);
		rskCourseEvaluate.setOperatorUser(operatorUser);
		rskCourseEvaluate.setOperatorTime(new Date());
		rskCourseEvaluateRepository.saveAndFlush(rskCourseEvaluate);
		return 1;
	}
	
	@Transactional
	public int delRskCourseEvaluate(Long id, Long operatorUser) {
		return rskCourseEvaluateRepository.delRskCourseEvaluateRepository(id, operatorUser);
	}

	@Transactional
	public int updateRskCourseEvaluate() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Transactional
	public int updateRskCourseEvaluateStatus(Long id, Integer commentStatus, Long operatorUser) {
		return rskCourseEvaluateRepository.updateRskCourseEvaluateStatus(id, commentStatus, operatorUser);
	}

	@Transactional
	public int updateRskCourseEvaluateTop(Long id, Integer isTop, Long operatorUser) {
		return rskCourseEvaluateRepository.updateRskCourseEvaluateTop(id, isTop, operatorUser);
	}

   
}
